<!--
 * @name: 
 * @version: 1.1.1
 * @Author: 刘大可
 * @Date: 2022-08-22 11:09:22
 * @LastEditors: 刘大可
 * @LastEditTime: 2022-09-09 15:47:36
-->
<template>
    <view>
        <!-- gc_school/pages/webview/index.wxml -->
        <web-view :src="url" @load="bindload"></web-view>
   </view>
</template>

<script>
// gc_school/pages/webview/index.js
var app = getApp()
import siteInfo from '@/siteinfo.js';
export default {
    data() {
        return {
            url: '',
			options:{},
			isLogin:false
        };
    }
    /**
        http://localhost:8081/h5/index/#/uni_modules/gc-curriculum/pages/index/index?
        wxapp_id=6&s_id=12&shareOpenid=ouMoB5AKEHFnyXecKXC_cj-4AU-k&openid=ouMoB5AKEHFnyXecKXC_cj-4AU-k&wxapp_id=6&s_id=12
     * 
     */
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
		// options.url =`/gc_school/pages/webview/index?url=https%3A%2F%2Fptfubu.gechuang.net%2Fh5%2F%23%2Funi_modules%2Fgc-curriculum%2Fpages%2Findex%2Findex%3FshareOpenid%3DooUiv5EV6jFDa2ZCRjKGHgnNG_SM%26wxapp_id%3D6%26s_id%3D12
// `
		console.log(options);
		console.log(options.url)

		options.url = decodeURIComponent(options.url)
		console.log(options.url)

		options.url = options.url.replace(/amp;/g,"")
		console.log(options.url)

		this.options=options
		
       
		this.initData(options)
        // options.url ="http://localhost:8081/h5/index/#/uni_modules/gc-curriculum/pages/index/index?wxapp_id=6&s_id=12&shareOpenid=ouMoB5AKEHFnyXecKXC_cj-4AU-k"
        // console.log(decodeURIComponent(options.url));

		
		
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
		
		if (this.isLogin==true) {
			uni.reLaunch({
				url:"/gc_school/pages/home/index"
			})
		}
	},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
		// return false
        let url = this.url.replace(/openid/g, "shareOpenid")
		console.log(url)
        var path = "/gc_school/pages/webview/index?url=" +encodeURIComponent( url)
		// path=encodeURIComponent(path)
        console.log(path);
        return {
            // title: "vip服务系统",
            path
        }
    },
    methods: {
		bindload(e){
			let url = e.detail.src
			
			console.log(url);
		},
		
		initData(options={}){
			var t = this;
			if(options.url.indexOf('h5/index')>-1||options.url.indexOf('gc-curriculum')>-1   )
			{
				if (!uni.getStorageSync("token")) {
					setTimeout(res=>{
						this.isLogin=true
					},1000)
					this.login().then((res)=>{
					    console.log("您已登陆！");
					},err=>{
						console.log(err);
					})
					
					return false
				}
				if(uni.getStorageSync('openid'))
				{
			        if (options.url.indexOf('shareOpenid') > -1) {
			            options.url = options.url + "&openid=" + uni.getStorageSync('openid')
			        } else {
			            options.url = options.url + "?openid=" + uni.getStorageSync('openid') + "&wxapp_id=" + siteInfo.uniacid + "&s_id=" + uni.getStorageSync('schoolId')
			
			        }
					t.url = options.url
				}else{
					app.globalData.util.request({
					    url: 'WechatUser/view',
					    data: {
					        s_id: uni.getStorageSync('schoolId')
					    },
					    success(res) {
							uni.setStorageSync('openid',res.data.data.openid)
							// console.log(res.data.data)
			                if (options.url.indexOf('shareOpenid') > -1) {
			                    options.url = options.url + "&openid=" + uni.getStorageSync('openid') 
			                    // + "&wxapp_id=" + siteInfo.uniacid + "&s_id=" + uni.getStorageSync('schoolId')
			                } else{
			                    options.url = options.url + "?openid=" + uni.getStorageSync('openid') + "&wxapp_id=" + siteInfo.uniacid + "&s_id=" + uni.getStorageSync('schoolId')
			
			                }
							t.url = options.url
						}
					},true)
				}
				
			}else{
				console.log(222)
				this.url = options.url
			}
		}
		
		
		
		
		
		
		
	}
};
</script>
<style>
/* gc_school/pages/webview/index.wxss */
</style>
